home *** CD-ROM | disk | FTP | other *** search
/ Otherware / Otherware_1_SB_Development.iso / mac / hypercar / mactool / thinkcgu.sit / app ƒ / morestr.c < prev    next >
Encoding:
C/C++ Source or Header  |  1990-11-20  |  1.7 KB  |  89 lines

  1. /*
  2. *    FILE:        morestr.c
  3. *    AUTHOR:        R. Gonzalez
  4. *    CREATED:    Sept 1, 1990
  5. *
  6. *    Defines more useful string functions.
  7. */
  8.  
  9. # include    <stdio.h>
  10. # include    <string.h>
  11. # include    <stdlib.h>
  12. # include    "morestr.h"
  13.  
  14. # define    MAX_LENGTH    80
  15.  
  16. /************************************************************************
  17. *    Usual function to get line from std. input.  Returns number of chars
  18. *    read or EOF.
  19. ************************************************************************/
  20. int        get_line(FILE *file,char line[],int max_length)
  21. {
  22.     int        c,
  23.             i=0;
  24.             
  25.     while (((c = fgetc(file)) != '\n') && c != EOF)
  26.         if (i < max_length - 1)
  27.             line[i++] = c;
  28.     
  29.     line[i] = '\0';
  30.     
  31.     if (c == EOF)
  32.         return EOF;
  33.     else
  34.         return i;
  35. }
  36.  
  37. /************************************************************************
  38. *    converts string to integer.  ascii only.
  39. ************************************************************************/
  40. int        strtoint(char *s)
  41. {
  42.     int        i = 0,
  43.             result = 0;
  44.     
  45.     while (s[i] == ' ')
  46.         i++;                /* strip leading spaces */
  47.     
  48.     while (s[i] > 47 && s[i] < 58)
  49.     {
  50.         result = result*10 + s[i] - 48;
  51.         i++;
  52.     }
  53.         
  54.     return result;
  55. }
  56.  
  57. /************************************************************************
  58. *    caseless version of strcmp() - only compares up to length of s2.
  59. *    ascii only.
  60. ************************************************************************/
  61. boolean        strsame(char *s1,char *s2)
  62. {
  63.     int        i;
  64.     char    c1,
  65.             c2;
  66.     boolean    equal = TRUE;
  67.     
  68.     if (strlen(s1) < strlen(s2))
  69.         equal = FALSE;
  70.     else
  71.         for (i=0 ; i<strlen(s2) ; i++)
  72.         {
  73.             if (s1[i] > 64 && s1[i] < 91)
  74.                 c1 = s1[i] + 32;        /* convert to lower-case */
  75.             else
  76.                 c1 = s1[i];
  77.             if (s2[i] > 64 && s2[i] < 91)
  78.                 c2 = s2[i] + 32;        /* convert to lower-case */
  79.             else
  80.                 c2 = s2[i];
  81.             if (c1 != c2)
  82.                 equal = FALSE;
  83.         }
  84.     
  85.     return equal;
  86. }
  87.  
  88.  
  89.